package me.zhengjie.modules.rest.enterprise;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.modules.domain.enterprise.EnterpriseFinancing;
import me.zhengjie.modules.service.EnterpriseFinService;
import me.zhengjie.modules.utils.Contents;
import me.zhengjie.modules.utils.JsonUtils;
import me.zhengjie.modules.utils.ReturnObject;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api("企业融资历史Api")
@RestController
@RequiredArgsConstructor
@RequestMapping("/enterFin")
public class EnterpriseFinController {

    private final EnterpriseFinService enterpriseFinService;

    @ApiOperation("根据企业名称查询融资历史信息")
    @AnonymousAccess
    @GetMapping("/queryEnterpriseFinByName")
    public List<EnterpriseFinancing> queryEnterpriseFinByName(String name){
        return enterpriseFinService.queryEnterpriseFinByName(name);
    }

    @ApiOperation("根据条件分页查询企业融资信息")
    @AnonymousAccess
    @GetMapping("/queryEnterpriseFinForPageByConditions")
    public Map<String,Object> queryEnterpriseFinForPageByConditions(String year,String[] round,@RequestParam Integer pageNo,@RequestParam Integer pageSize){
        Map<String,Object> map=new HashMap<>();
        if(round!=null&&round.length==0){
            round=null;
        }
        if(year!=null&&year.equals("")){
            System.out.println(year);
            year=null;
        }
        map.put("round",round);
        map.put("year",year);
        map.put("pageNo",(pageNo-1)*pageSize);
        map.put("pageSize",pageSize);
        List<EnterpriseFinancing> list=enterpriseFinService.queryEnterpriseFinForPageByConditions(map);
        int total=enterpriseFinService.queryEnterpriseFinForPageByConditionsToTotal(map);
        map=new HashMap<>();
        map.put("list",list);
        map.put("total",total);
        return map;
    }

    @ApiOperation("统计企业融资论次,和披露时间")
    @AnonymousAccess
    @GetMapping("/queryFinInfo")
    public Map<String, Object> queryRound(){
        Map<String, Object> map=new HashMap<>();
        List<String> round=enterpriseFinService.queryRound();
        List<String> pubDate=enterpriseFinService.queryPubTime();
        map.put("round",round);
        map.put("pubDate",pubDate);
        return map;
    }
}
